package com.iflytek.view;

import com.iflytek.bean.Emp;
import com.iflytek.service.EmpService;
import com.iflytek.service.Impl.EmpServiceImpl;

import java.util.List;
import java.util.Scanner;


public class EmpMain {
    static Scanner sc = new Scanner(System.in);
    static EmpService empService= new EmpServiceImpl();
    static int empno;
    static String empnoA;
    static String regex1 = "^\\d{4}$";

    /**
     *
     *程序启动入口
     */

    public static void main(String[] args) {
        System.out.println("******************************");
        System.out.println("**********员工管理系统***********");
        System.out.println("******************************");
        menu();
    }

    /**
     *  程序欢迎菜单
     */
    private static void menu() {
        System.out.println("请输入相应操作序号:\n 1.员工列表\n 2.增加员工\n 3.修改员工信息\n 4.删除员工\n 5.根据员工姓名模糊查询\n 6.退出");
        int num=sc.nextInt();
        switch (num){
            case 1:
                List<Emp> empList=empService.getAllEmp();
                for (Emp emp : empList){
                    System.out.println(emp);
                }
                System.out.println("查询成功!!");
                break;

            case 2:
                empService.addEmp(new Emp());
                System.out.println("添加成功!!");
                break;

            case 3:
                do {
                    System.out.println("请输入要修改的员工编号(四位数): ");
                    empnoA = sc.next();
                    if (empnoA.matches(regex1)){
                        empno = Integer.parseInt(empnoA);
                        break;
                    }else {
                        System.out.println("输入错误,请重新输入!!!\n============");
                    }
                }while (true);
                empService.upDate(empno);
                System.out.println("修改成功!!");
                break;

            case 4:
                do {
                    System.out.println("请输入要修改信息的员工编号(四位数)：");
                    empnoA= sc.next();
                    if (empnoA.matches(regex1)){
                        empno = Integer.parseInt(empnoA);
                        break;
                    }else {
                        System.out.println("输入错误，请重新输入！！！\n============");
                    }
                } while (true);
                empService.delEmpById(empno);
                System.out.println("删除成功！！");
                break;

            case 5:
                System.out.println("请输入要模糊查询的内容：");
                String ename =sc.next();
                List<Emp> empList1 = empService.selectLikeName(ename);
                for (Emp emp : empList1) {
                    System.out.println(emp);
                }
                break;

            case 6:
                System.out.println("正在退出！！");
                System.exit(0);
                break;

            default:
                System.out.println("输入错误,请重新输入!!!\n============");
                menu();
        }
        menu();
    }

}
